package com.alibaba.controller;

import com.alibaba.annotation.SystemLog;
import com.alibaba.define.domain.vo.ArticleDetailVO;
import com.alibaba.define.domain.vo.HotArticleVO;
import com.alibaba.common.ResponseResult;
import com.alibaba.define.domain.vo.PageVO;
import com.alibaba.define.service.ArticleService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * @author : hanyang
 * @date : 2023-10-29 13:28
 **/

@Slf4j
@RestController
@RequestMapping("/article")
public class ArticleController {

    @Resource
    ArticleService articleService;

    @GetMapping("/hotArticleList")
    @SystemLog(businessName = "查询热门文章列表")
    public ResponseResult<List<HotArticleVO>> hotArticleList() {
        log.info("query hotArticleList...");
        return articleService.hotArticleList();
    }

    @GetMapping("/articleList")
    @SystemLog(businessName = "查询文章列表")
    public ResponseResult<PageVO> articleList(Integer pageNum, Integer pageSize, Long categoryId) {
        log.info("query articleList [request pageNum:{} | pageSize:{} | categoryId:{}]", pageNum, pageSize, categoryId);
        return articleService.articleList(pageNum, pageSize, categoryId);
    }

    @GetMapping("/{id}")
    @SystemLog(businessName = "查询文章详情")
    public ResponseResult<ArticleDetailVO> getArticleDetail(@PathVariable("id") Long id) {
        log.info("query articleById [request id:{}]", id);
        return articleService.getArticleDetailById(id);
    }

    @PutMapping("/updateViewCount/{id}")
    @SystemLog(businessName = "文章浏览量新增")
    public ResponseResult<Void> updateViewCount(@PathVariable("id") Long id) {
        log.info("update article viewCount [request id:{}]", id);
        return articleService.updateArticleViewCount(id);
    }
}
